package com.vipbbo.spring.bean.customtag;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

public class MyBeanDefinitionParser implements BeanDefinitionParser {

	private final Class<?> beanClass;

	public MyBeanDefinitionParser(Class<?> beanClass) {
		this.beanClass = beanClass;
	}


	@Override
	public BeanDefinition parse(Element element, ParserContext parserContext) {
		GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition();
		genericBeanDefinition.setBeanClass(beanClass);
		genericBeanDefinition.setLazyInit(false);
		genericBeanDefinition.getPropertyValues().add("name", element.getAttribute("name"));
		genericBeanDefinition.getPropertyValues().add("age", element.getAttribute("age"));
		parserContext.getRegistry().registerBeanDefinition(beanClass.getName(),genericBeanDefinition);
		return null;
	}
}
